package com.android.clinic.doctors.app.utils;

import android.content.Context;
import android.util.TypedValue;

import com.android.clinic.doctors.app.ClinicDoctorsApplication;

/**
 * Created by cheng on 2018/6/12.
 */
public class DisplayUtil {

    /**
     * convert the dip value to px value
     *
     * @param
     * @param dipValue
     * @return
     */
    public static int dip2px(float dipValue) {
        float scale = ClinicDoctorsApplication.getInstance().getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
    }

    /**
     * dpתpx
     */
    public static int dip2px(Context ctx, float dpValue) {
        final float scale = ctx.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    /**
     * method desc: px -> dip
     *
     * @param pxValue
     * @return
     */
    public static int px2dip(int pxValue) {
        float reSize = ClinicDoctorsApplication.getInstance().getResources().getDisplayMetrics().density;
        return (int) ((pxValue / reSize) + 0.5);
    }

    /**
     * method desc：sp -> px
     *
     * @param spValue
     * @return
     */
    public static float sp2px(int spValue) {
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue,
                ClinicDoctorsApplication.getInstance().getResources().getDisplayMetrics());
    }

    public static int getScreenWidth() {
        return ClinicDoctorsApplication.getInstance().getResources().getDisplayMetrics().widthPixels;
    }

    public static int getScreenHeight() {
        return ClinicDoctorsApplication.getInstance().getResources().getDisplayMetrics().heightPixels;
    }

}
